from datetime import timedelta

from temporalio import workflow

with workflow.unsafe.imports_passed_through():
    from activities import post_patch_activity

"""dacx
After ensuring that all Workflows started with `pre_patch_activity` code have finished, you can [deprecate the patch](https://python.temporal.io/temporalio.workflow.html#deprecate_patch).

Deprecated patches serve as a bridge between `pre_patch_activity` and `post_patch_activity`. They function similarly to regular patches by adding a marker to the Workflow History. However, this marker won't cause a replay failure when the Workflow code doesn't produce it.

If, during the deployment of `post_patch_activity`, there are still live Workers running `pre_patch_activity` code and these Workers pick up Workflow histories generated by `post_patch_activity`, they will safely use the patched branch.
dacx"""


@workflow.defn
class MyWorkflow:
    @workflow.run
    async def run(self) -> None:
        workflow.deprecate_patch("my-patch")
        self._result = await workflow.execute_activity(
            post_patch_activity,
            schedule_to_close_timeout=timedelta(minutes=5),
        )

    @workflow.query
    def result(self) -> str:
        return self._result


""" @dacx
id: understanding-deprecated-patches-in-python-sdk
title: Understanding deprecated Patches in the Python SDK
label: Deprecated Patches
description: An overview of deprecated patches in the Python SDK, detailing their role in ensuring smooth transitions between workflow versions and preventing replay failures.
tags:
 - deprecated patches
 - python sdk
 - workflow transition
 - best practices
lines: 8-14, 17-25
@dacx """
